aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/fund/[id]/+page.server.ts
blob: 9ea33627aebe9bfb122100cd7c38d7a3f59d3e09 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import getRates from "$lib/rates";
import { auth, get, post } from "$lib/utils";
import { redirect } from "@sveltejs/kit";

export const load = async ({ depends, params: { id }, parent }) => {
	depends("app:payments");
	const data = await get(`/fund/${id}`);
	const rates = await getRates();
	const { user } = await parent();
	data.rate = rates[user?.currency || "USD"];
	return data;
};

export const actions = {
	default: async ({ cookies, locals, params }) => {
		const { user } = locals;

		if (user) {
			await post("/redeem", params, auth(cookies));
			redirect(307, "/payments");
		}

		redirect(307, "/register");
	},
};